package org.lgiavedoni.android.franq.core.listener;

import org.lgiavedoni.android.franq.service.phone.ContextService;

import android.content.Context;
import android.telephony.TelephonyManager;

public abstract class PhoneStateListener extends android.telephony.PhoneStateListener implements PhoneListener {

	public abstract int getEventListener();

	private boolean listening = false;

	@Override
	public void registerListener() {
		TelephonyManager telephony = (TelephonyManager) ContextService.inst.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
		telephony.listen(this, getEventListener());
		listening = true;
	}

	@Override
	public void unregisterListener() {
		TelephonyManager telephony = (TelephonyManager) ContextService.inst.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
		telephony.listen(this, PhoneStateListener.LISTEN_NONE);
		listening = false;
	}

	public boolean isListening() {
		return listening;
	}

}
